package servlet;

import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/api/try")
public class Try extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        String a="HH";

        Gson aa=new Gson();

        writer.print(aa.toJson(a));
        writer.flush();
        writer.close();



        // 1.通过DAO获取数据库的数据
//        ProductDao productDao = new ProductDaoImpl() ;
//        List<Product> list = productDao.selectAll();
//
//        resp.setContentType("application/json;charset=utf-8");
//        PrintWriter out = resp.getWriter();
//        // 2. 对数据进行处理（格式） -- 先封装到DTO对象中，后再序列为JSON字符串
//        ResultDto resultDto = successJson(list);
//        String json = new Gson().toJson(resultDto);
//
//        // 3.响应数据到客户端浏览器中
//        out.print(json);
//
//        out.flush();
//        out.close();
    }
}
